//
//  DiscoverTrainListViewController.m
//  HJB
//
//  Created by jiezsoft.com on 14-10-10.
//  Copyright (c) 2014年 jiezsoft.com. All rights reserved.
//

#import "DiscoverSupplyListViewController.h"
#import "DiscoverSupplyDetailProductViewController.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "CycleScrollViews.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "UIButton+WebCache.h"
#import "biaoqianCell.h"
//#import "EventDetailsViewController.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "biaoqianmodel.h"
@interface DiscoverSupplyListViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;
@property(nonatomic,strong)NSString*sta;

@end

@implementation DiscoverSupplyListViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*fid;
    NSMutableArray*title;
    NSMutableArray*code;
    NSMutableArray*content1;
    NSMutableArray*content;
    NSMutableArray*imageUrl;
    NSMutableArray*author;
    NSMutableArray*pubTime;
    NSMutableArray*collectCount;
    NSMutableArray*commentCount;
    NSMutableArray*LinkType;
    NSMutableArray*LinkCode;
    NSMutableArray*ImageUrl;
     NSMutableArray *allComment;
    NSString*TotalCount;
    CycleScrollViews *mainScorllView;
    NSString *result;
    float lastContentOffset;
    int pageNumber;
    UIButton*diseview;
    UIView*view;
    BOOL saveAccount;
    UILabel* noLabel;
}
@synthesize alt = alt;


- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    UIView *titleView = [[UIView alloc] init] ;
    titleView.frame = CGRectMake(0, 0, 150, 44);
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.frame = CGRectMake(0, 10, 150, 20);
    self.titleLabel.font = [UIFont systemFontOfSize:tetlefot];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.textColor = [UIColor blackColor];
    [titleView addSubview:self.titleLabel];
    
    self.navigationItem.titleView = titleView;
    
    UIButton* xuanxiang=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150,44 )];
    [xuanxiang addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview:xuanxiang];
    UIButton*sxBtn111 = [[UIButton alloc] initWithFrame:CGRectMake(120, 13.0,  15, 15)];
    [sxBtn111 setImage:[UIImage imageNamed:@"lusejiantou"] forState:UIControlStateNormal];
    [sxBtn111 addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview:sxBtn111];
    saveAccount=YES;
    self.titleLabel.text = @"全部货源";
    
}
-(void)closeKeyBoad
{
    saveAccount=YES;
    [diseview removeFromSuperview];
    [view removeFromSuperview];
    [diseview removeFromSuperview];
}
-(void)add:(UIButton*)sender{
    
    
    [view removeFromSuperview];
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight)];
    view.backgroundColor=[UIColor clearColor];
    [self.view addSubview:view];
    
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [view addGestureRecognizer:singleFingerOne];
    
    saveAccount=! saveAccount;
    
    if (!saveAccount) {
        diseview=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, 0, 200, 50*content1.count)];
        [diseview setBackgroundImage:[UIImage imageNamed:@"kuang"] forState:UIControlStateNormal];
        [view addSubview:diseview];
        
//        NSArray *array = @[@"全部货源",@"家居建材",@"厨房卫浴",@"居家家纺",@"家装灯饰",];
        //      NSArray *arraycol = @[[UIColor blackColor],[UIColor whiteColor],[UIColor whiteColor],[UIColor whiteColor],[UIColor whiteColor]];
        for (int i = 0; i<content1.count; i++) {
            
            UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
            shanghubutton.frame = CGRectMake(0, 5+50*i, 200, 50);
            
            shanghubutton.tag = i;
            [shanghubutton setTitle:[content1 objectAtIndex:i] forState:UIControlStateNormal];
            if ([self.titleLabel.text isEqualToString:[content1 objectAtIndex:i]]) {
                [shanghubutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            }else{
                [shanghubutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }
            
            shanghubutton.titleLabel.font=[UIFont systemFontOfSize:15];
            [shanghubutton addTarget:self action:@selector(shanghubuttonimage:) forControlEvents:UIControlEventTouchUpInside];
            [diseview addSubview:shanghubutton];
            
            UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(10, 5+50*i, 200-20, 0.35)];
            line.backgroundColor=luseColor;
            [diseview addSubview:line];
            
        }
        
    }else{
        
        [diseview removeFromSuperview];
        
        
    }
    
}
- (void)shanghubuttonimage:(UIButton *)button{
    
    
    [diseview removeFromSuperview];
    [view removeFromSuperview];
    [diseview removeFromSuperview];
    _sta=[NSString stringWithFormat:@"%@", code[button.tag]];
    [self add];
    self.titleLabel.text = button.titleLabel.text;
//    if (button.tag==302) {
//        
//        
//        
//        
//    }
//    
//    if (button.tag==301) {
//        [diseview removeFromSuperview];
//        [view removeFromSuperview];
//        [diseview removeFromSuperview];
//        _sta=@"";
//        [self add];
//        self.titleLabel.text = button.titleLabel.text;
//        
//    }
//    if (button.tag==303) {
//        [diseview removeFromSuperview];
//        [view removeFromSuperview];
//        [diseview removeFromSuperview];
//        _sta=[NSString stringWithFormat:@"%@", @"S002"];
//        self.titleLabel.text = button.titleLabel.text;
//        [self add];
//    }
//    if (button.tag==304) {
//        [diseview removeFromSuperview];
//        [view removeFromSuperview];
//        [diseview removeFromSuperview];
//        _sta=[NSString stringWithFormat:@"%@", @"S003"];
//        self.titleLabel.text = button.titleLabel.text;
//        [self add];
//    }
//    if (button.tag==305) {
//        [diseview removeFromSuperview];
//        [view removeFromSuperview];
//        [diseview removeFromSuperview];
//        _sta=[NSString stringWithFormat:@"%@", @"S004"];
//        self.titleLabel.text = button.titleLabel.text;
//        [self add];
//    }
    
}



- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    
    [self add];
    
    [self addFooter];
    [self addheader];
    
    
    
    
    code=[[NSMutableArray alloc]init];
    content1=[[NSMutableArray alloc]init];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"SupplyType" forKey:@"optionName"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"System/AppCodes" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [code addObject:[dicc valueForKey:@"code"]];
                    [content1 addObject:[dicc valueForKey:@"content"]];
                    
                    
                }
            
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];

    
    
    
    
    
    
    
    
}
-(void)add{
   saveAccount=YES;
    pageNumber=1;
    pubTime= [[NSMutableArray alloc] init];
    author= [[NSMutableArray alloc] init];
    imageUrl= [[NSMutableArray alloc] init];
    content= [[NSMutableArray alloc] init];
    title= [[NSMutableArray alloc] init];
    fid= [[NSMutableArray alloc] init];
    LinkType= [[NSMutableArray alloc] init];
    LinkCode= [[NSMutableArray alloc] init];
    ImageUrl= [[NSMutableArray alloc] init];
    
    self.title=@"全部货源";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    commdity=[HAODEsingleton shared];
    
//    _table.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    [_table registerNib:[UINib nibWithNibName:@"biaoqianCell" bundle:nil] forCellReuseIdentifier:@"biaoqianCell"];
   
    [self.view addSubview:_table];

    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"1" forKey:@"StarIndex"];
    [param setValue:@"20" forKey:@"PageSize"];
    [param setValue:_sta forKey:@"typeCode"];
    
    NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"/Discover/Supply/List" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) { NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                [self setupCouponCommentView:severDataDict.dataDict];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    
//                    [author addObject:[dicc valueForKey:@"intro"]];
                    [ImageUrl addObject:[dicc valueForKey:@"imageUrl"]];
                   [content addObject:[dicc valueForKey:@"details"]];
                    [fid addObject:[dicc valueForKey:@"fid"]];
                    [title addObject:[dicc valueForKey:@"title"]];
//                    
//                    NSString* string =  [dicc valueForKey:@"pubTime"];
//                    NSLog(@"-------------%@",string);
//                    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//                    [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
//                    NSDate *destDate= [dateFormatter dateFromString:string];
//                    
//                    NSTimeInterval  timeInterval = [destDate timeIntervalSinceNow];
//                    timeInterval = -timeInterval;
//                    
//                    
//                    
//                    long temp = 0;
//                    
//                    if (timeInterval < 60) {
//                        result = [NSString stringWithFormat:@"刚刚"];
//                    }
//                    else if((temp = timeInterval/60) <60){
//                        result = [NSString stringWithFormat:@"%ld分前",temp];
//                    }
//                    
//                    else if((temp = temp/60) <24){
//                        result = [NSString stringWithFormat:@"%ld小时前",temp];
//                    }
//                    
//                    else if((temp = temp/24) <30){
//                        result = [NSString stringWithFormat:@"%ld天前",temp];
//                    }
//                    
//                    else if((temp = temp/30) <12){
//                        result = [NSString stringWithFormat:@"%ld月前",temp];
//                    }
//                    else{
//                        temp = temp/12;
//                        result = [NSString stringWithFormat:@"%ld年前",temp];
//                    }
//                    
//                    
//                    [pubTime addObject:result];
//                    
//                    
                }

                if (arrr.count>0) {
                    [self _AutoScrollView];
                    
                }
                
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    

    
}

//上拉刷新
- (void)addFooter
{
    
    
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        if (TotalCount.intValue/20>=pageNumber) {
            pageNumber++;
            
            NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
            NSString* tokenId = [user1 objectForKey:@"tokenId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:tokenId forKey:@"tokenId"];
          
            [params setValue:@"20" forKey:@"pageSize"];
            [params setValue:_sta forKey:@"typeCode"];
            [params setValue:[NSString stringWithFormat:@"%d" ,pageNumber] forKey:@"pageIndex"];
            
            NSLog(@"-----%@",params);
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
            [HttpRequest requestData:@"/Discover/Supply/List" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"-----%@",severDataDict.dataDict);
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                         NSMutableArray* arr=[[NSMutableArray alloc]init];
                        arr=[severDataDict.dataDict objectForKey:@"DataLine"];
                        if (arr.count>0) {
                            [allComment  removeAllObjects];
                            [title  removeAllObjects];
                            [ImageUrl  removeAllObjects];
                            [fid  removeAllObjects];
                            [content  removeAllObjects];
                            
                            [self setupCouponCommentView:severDataDict.dataDict];
                            for (NSDictionary* dicc in arr )
                            {
                                
                                [ImageUrl addObject:[dicc valueForKey:@"imageUrl"]];
                                [content addObject:[dicc valueForKey:@"details"]];
                                [fid addObject:[dicc valueForKey:@"fid"]];
                                [title addObject:[dicc valueForKey:@"title"]];

                                
                            }
                            
                        }
                        
                        
                        
                        
                    }else{
                        
                        
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        
                        
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
        }else{
            
            NSString *requestResultStr=@"没有更多数据了！";
            // [Global showTextHud:requestResultStr view:self.view];
            [Global showTextHudSub:requestResultStr view:self.view];
            
            
        }
        
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
    
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}
//下拉刷新
- (void)addheader
{
    
    
    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        
        [self add];
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}



- (void)setupCouponCommentView:(NSDictionary *)dic{
    
    NSMutableArray *commentArray = [dic objectForKey:@"DataLine"];
    
  
  
    allComment = [NSMutableArray array];
    for (int i = 0; i<commentArray.count; i++) {
        
        NSMutableDictionary *dataDic = commentArray[i];
        if (![dataDic isKindOfClass:[NSNull class]]){
            
            NSArray *commentPicArray = [dataDic objectForKey:@"tagList"];
            
            
            biaoqianmodel *cModel = [[biaoqianmodel alloc]init];
            
            cModel.userName = [dataDic objectForKey:@"intro"];
            cModel.title = [dataDic objectForKey:@"title"];
            cModel.createdAt = [dataDic objectForKey:@"pubTime"];
            cModel.headImageUrl = [dataDic objectForKey:@"imageUrl"];
           
            NSMutableArray *fakeCommentImagesSmall = [NSMutableArray array];
            NSMutableArray *fakeCommentImagesBig = [NSMutableArray array];
            for (NSDictionary *picDic in commentPicArray) {
                [fakeCommentImagesSmall addObject:[picDic objectForKey:@"content"]];
                [fakeCommentImagesBig addObject:[picDic objectForKey:@"content"]];
            }
            cModel.imagePicSmall = fakeCommentImagesSmall;
            cModel.imagePicBig = fakeCommentImagesBig;
            [allComment addObject:cModel];
        }
    
    
    
    }
    
    if (commentArray.count>1) {
        
        [allComment removeObjectAtIndex:0];
    
    }
    [_table reloadData];
}



#pragma mark - TableView dataSource && delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return allComment.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    static NSString *identifier = @"biaoqianCell";

     biaoqianCell *cell = (biaoqianCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"biaoqianCell" owner:self options:nil][0];
    }else{
        //cell中本来就有一个subview，如果是重用cell，则把cell中自己添加的subview清除掉，避免出现重叠问题
        //         [[cell.subviews objectAtIndex:1] removeFromSuperview];
        
    }
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    
    
    
    biaoqianmodel *cModel = [[biaoqianmodel alloc]init];
    
    cModel = allComment[indexPath.row];
    cell.comment = cModel;
    
    
    
    if (title.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 90-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    if (title.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 90-0.35, ScreenWidth, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }

    
    
    
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  90;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
                    if (fid.count>1) {
                                            [fid removeObjectAtIndex:0];
    
                    }

    commdity.reqId=fid[indexPath.row];
    commdity.ImageUrl=ImageUrl[indexPath.row];
    commdity.content=content[indexPath.row];
    commdity.title=title[indexPath.row];
    NSLog(@"-------%@",commdity.reqId);
    DiscoverSupplyDetailProductViewController *detailViewController = [[DiscoverSupplyDetailProductViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    //
    
    
    
    
}




- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

//轮播视图
- (void )_AutoScrollView {
    
    commdity.ImageUrl=[ImageUrl objectAtIndex:0];
    commdity.content=[content objectAtIndex:0];
    commdity.title=[title objectAtIndex:0];
    UIButton* button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 210)];
    [button setTitle:[fid objectAtIndex:0] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    
    button.contentMode = UIViewContentModeScaleAspectFill;
    [button setImageWithURL:[NSURL URLWithString:[ImageUrl objectAtIndex:0]] placeholderImage:[UIImage imageNamed:@""]];
    
    [button  addTarget:self action:@selector(Btn:) forControlEvents:UIControlEventTouchUpInside];
    UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(0,350/2, ScreenWidth, 210-350/2)];
    label1.text=[NSString stringWithFormat:@"  %@",[title objectAtIndex:0]];
    label1.backgroundColor=[UIColor blackColor];
    label1.alpha=0.5;
    label1.font=[UIFont systemFontOfSize:16];
    [button addSubview:label1];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0,350/2, ScreenWidth, 210-350/2)];
    label.text=[NSString stringWithFormat:@"  %@",[title objectAtIndex:0]];
    label.textColor=[UIColor whiteColor];
    label.font=[UIFont systemFontOfSize:16];
    [button addSubview:label];
    
    _table. tableHeaderView=button;
    
}

-(void)Btn:(UIButton*)sender{
    
    commdity.reqId=sender.titleLabel.text;
    
   
    //
    //    commdity.ConditDesp=[ConditDesp objectAtIndex:indexPath.row];
    //    commdity.LastDate1= [LastDate objectAtIndex:indexPath.row];
    DiscoverSupplyDetailProductViewController *detailViewController = [[DiscoverSupplyDetailProductViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    //
    
    
    
}

-(void)jiazai1{
    //    [jiazai removeFromSuperview];
    [self _AutoScrollView];
    
}


@end
